package com.yjt.javatest.expression;

import com.yjt.javatest.entity.LoginUser;
import com.yjt.javatest.entity.UserType;
import com.yjt.javatest.utils.SecurityUtil;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("ex")
public class ExpressionRoot {

    public boolean hasAuthority(String authority){
        //获取当前用户的权限
        LoginUser loginUser = SecurityUtil.getLoginUser();
        List<String> permissions = loginUser.getPermissions();
        //判断用户权限集合中是否存在authority
        return permissions.contains(UserType.ADMIN.getName()) || permissions.contains(authority);
    }
    public boolean hasAuthority(UserType userType){
        //获取当前用户的权限
        LoginUser loginUser = SecurityUtil.getLoginUser();
        List<String> permissions = loginUser.getPermissions();
        //判断用户权限集合中是否存在authority
        return permissions.contains(UserType.ADMIN.getName()) || permissions.contains(userType.getName());
    }
    public boolean isTeacher(){
        //获取当前用户的权限
        return hasAuthority(UserType.TEACHER);
    }
    public boolean isStudent(){
        //获取当前用户的权限
        return hasAuthority(UserType.STUDENT);
    }
    public boolean isAdmin(){
        //获取当前用户的权限
        return hasAuthority(UserType.ADMIN);
    }
}
